#include "stb_rect_pack.h"
#include "fxcc/core/graph/common/ImageMipmap.h"
#include "fxcc/core/AssertManager.h"

int main()
{
	std::vector<std::string> paths =
	{
		fxcc::AssertManager::GetRelativeFile("skybox/back.jpg"),
		fxcc::AssertManager::GetRelativeFile("skybox/bottom.jpg"),
		fxcc::AssertManager::GetRelativeFile("skybox/front.jpg"),
		fxcc::AssertManager::GetRelativeFile("skybox/left.jpg"),
		fxcc::AssertManager::GetRelativeFile("skybox/right.jpg"),
		fxcc::AssertManager::GetRelativeFile("skybox/top.jpg"),
		fxcc::AssertManager::GetRelativeFile("pbr/grass/albedo.png"),
		fxcc::AssertManager::GetRelativeFile("pbr/grass/ao.png"),
		fxcc::AssertManager::GetRelativeFile("pbr/grass/normal.png"),

	};

	std::vector<std::shared_ptr<fxcc::graph::common::ImageMipmap>> m_Images;

	glm::ivec2 outGridNum(3, 3);

	for (int i = 0; i < paths.size(); i++)
	{
		fxcc::graph::common::ImageMipmap::Desc desc;
		desc.m_wicPath = paths[i];
		desc.m_wicHdr = false;
		desc.m_wicReq = 3;

		auto image = std::make_shared<fxcc::graph::common::ImageMipmap>(desc);
		m_Images.push_back(image);
	}
	
	int numGrids = outGridNum.x * outGridNum.y;

	if (m_Images.size() > numGrids)
	{
		printf("max size > grid num x*y %d", outGridNum.x * outGridNum.y);
		return 0;
	}

	fxcc::graph::common::ImageMipmap::MipMapData outImage = m_Images[0]->m_WICTexture;
	outImage.m_Width *= outGridNum.x;
	outImage.m_Height *= outGridNum.y;
	outImage.InitData();

	for (int i = 0; i < m_Images.size(); i++)
	{
		int row = i / 3;
		int col = i % 3;

		const auto& sourceImage = m_Images[i]->m_WICTexture;
	
		outImage.DrawRect(sourceImage, glm::ivec2(3, 3), glm::ivec2(col, row));
	}

	std::string path = "sub.bmp";

	if (fs::exists(path))
	{
		fs::remove(path);
	}
	outImage.SaveBMP("sub.bmp");
	return 0;
		

}